package com.zj.juc.study.lockSupport;

import java.util.concurrent.locks.LockSupport;

/**
 * @author 自己的名字
 * @version 1.0.0
 * @ClassName LockSupportParkAndUnParkDemo
 * @Description LockSupport的park和unpark
 * @createTime 2024年12月26日 23:18
 */
public class LockSupportParkAndUnParkDemo {

    public static void main(String[] args) {
        Thread thread = new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "\t.....come in");
            LockSupport.park();//没有许可证，阻塞
            System.out.println(Thread.currentThread().getName()+"\t....被唤醒");
        }, "t1");
        thread.start();

        new Thread(()->{
            LockSupport.unpark(thread);//给予许可证，放行
            System.out.println(Thread.currentThread().getName()+"\t....放行");

        },"t2").start();
    }
}
